﻿#region zh-CHS 2006 - 2007 DemoSoft 团队 | en 2006 - 2007 DemoSoft Team

//     NOTES
// ---------------
//
// This file is a part of the G.O.S.E(Game Online Server Engine) for .NET.
//
//                 2006-2007 DemoSoft Team
//
//
// First Version : by H.Q.Cai - mailto:caihuanqing@hotmail.com

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published
 *   by the Free Software Foundation; either version 2.1 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

#region zh-CHS 包含名字空间 | en Include namespace
using System;
using System.Text;
using System.Collections.Generic;
using Demo_G.O.S.E.ServerEngine.Util;
using Demo_G.O.S.E.ServerEngine.Common;
using Demo_G.O.S.E.ServerEngine.Creature;
using Demo_G.O.S.E.ServerEngine.Network;
#endregion

namespace Demo_G.O.S.E.ServerEngine.Guild
{
    /// <summary>
    /// 
    /// </summary>
    public abstract class BaseGuild
    {
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private static int s_NextID = 1;
        #endregion

        #region zh-CHS 构造和初始化和清理 | en Constructors and Initializers and Dispose
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Id"></param>
        public BaseGuild( int iID ) // serialization ctor
        {
            m_Id = iID;
            s_GuildList.Add( m_Id, this );
            if ( m_Id + 1 > s_NextID )
                s_NextID = m_Id + 1;
        }

        /// <summary>
        /// 
        /// </summary>
        public BaseGuild()
        {
            m_Id = s_NextID++;
            s_GuildList.Add( m_Id, this );
        }
        #endregion

        #region zh-CHS 静态属性 | en Static Properties
        /// <summary>
        /// 
        /// </summary>
        private static Dictionary<int, BaseGuild> s_GuildList = new Dictionary<int, BaseGuild>();
        /// <summary>
        /// 
        /// </summary>
        public static Dictionary<int, BaseGuild> List
        {
            get { return s_GuildList; }
        }
        #endregion

        #region zh-CHS 属性 | en Properties
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private int m_Id;
        #endregion
        /// <summary>
        /// 
        /// </summary>
        [CommandProperty( AccessLevel.Counselor )]
        public int Id
        {
            get { return m_Id; }
        }

        #endregion

        #region zh-CHS 抽象方法 | en Abstract Method
        /// <summary>
        /// 
        /// </summary>
        public abstract string Abbreviation { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public abstract string Name { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public abstract GuildType Type { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public abstract bool Disbanded { get; }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="baseMobile"></param>
        public abstract void OnDelete( BaseCreature baseMobile );
        #endregion

        #region zh-CHS 方法 | en Method
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return String.Format( "0x{0:X} \"{1} [{2}]\"", m_Id, Name, Abbreviation );
        }
        #endregion

        #region zh-CHS 静态方法 | en Static Method
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static BaseGuild Find( int id )
        {
            BaseGuild g;

            s_GuildList.TryGetValue( id, out g );

            return g;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static BaseGuild FindByName( string name )
        {
            foreach ( BaseGuild g in s_GuildList.Values )
            {
                if ( g.Name == name )
                    return g;
            }

            return null;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="abbr"></param>
        /// <returns></returns>
        public static BaseGuild FindByAbbrev( string abbr )
        {
            foreach ( BaseGuild g in s_GuildList.Values )
            {
                if ( g.Abbreviation == abbr )
                    return g;
            }

            return null;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="find"></param>
        /// <returns></returns>
        public static List<BaseGuild> Search( string find )
        {
            string[] words = find.ToLower().Split( ' ' );
            List<BaseGuild> results = new List<BaseGuild>();

            foreach ( BaseGuild g in s_GuildList.Values )
            {
                bool match = true;
                string name = g.Name.ToLower();
                for ( int i = 0; i < words.Length; i++ )
                {
                    if ( name.IndexOf( words[i] ) == -1 )
                    {
                        match = false;
                        break;
                    }
                }

                if ( match )
                    results.Add( g );
            }

            return results;
        }
        #endregion
    }
}
#endregion

